<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    <title>Title</title>
</head>
<body>
<div class="container">

<div class="row">
    <div class="col-md-4">
        <button class="btn btn-info"><a href="/admin/tclasshome" class="glyphicon glyphicon-chevron-left">返回</a></button>
    </div>
</div>
    <div class="row">
        <div class="col-md-12">
            <table class="table table-hover" id="tbd">
                <thead>
                <tr>
                    <td>#</td>
                    <td>学号</td>
                    <td>姓名</td>
                    <td>班级</td>
                </tr>
                </thead>
                <tbody>
                <#list users as member>
                <tr>
                    <td>${member.id}</td>
                    <td>${member.code}</td>
                    <td>${member.name}</td>
                    <td>${classname}</td>

                <td><button type="button" class="btn btn-success"><span class="glyphicon glyphicon-pencil edit_btn" onclick="editbut(${member.id})">编辑</span></button>
                    <button class="btn btn-danger"><span class="glyphicon glyphicon-trash del_btn" onclick="delbut(${member.id})">删除</span></button>
                </td>

                </tr>
                </#list>
                </tbody>
            </table>
        </div>
    </div>
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <form>
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">增加班级</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal">

                        <div class="form-group">
                            <label  class="col-sm-2 control-label">班级名</label>
                            <div class="col-sm-10">
                                <input type="text" name="name" class="form-control" id="name" placeholder="name">
                            </div>
                        </div>
                        <div class="form-group">
                            <label  class="col-sm-2 control-label">入学时间</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="time" placeholder="time" name="time">
                            </div>
                        </div>
                        <div class="form-group">
                            <label  class="col-sm-2 control-label">班主任</label>
                            <div class="col-sm-10">
                                <select class="form-control" id="usetype" name="managerid">
                                    <#list tclasses as tclass>
                                        <option value="${tclass.id}">${tclass.name}</option>
                                    </#list>

                                </select>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="addbutt">提交更改</button>
                </div>
            </div><!-- /.modal-content -->
        </form>
    </div><!-- /.modal -->
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="editeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="">编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">编号</label>
                        <div class="col-sm-10">
                            <input class="form-control" type="text" id="eid" name="studentid" placeholder="" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">学号</label>
                        <div class="col-sm-10">
                            <input class="form-control" type="text" name="学号" placeholder=""  id="ename" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="col-sm-2 control-label">姓名</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control"  placeholder="姓名" name="year" id="etime" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="col-sm-2 control-label">班级</label>
                        <div class="col-sm-10">
                            <select class="form-control"  name="classid">
                                <#list tclasses as tclass>
                                <option value="${tclass.id}">${tclass.name}</option>
                            </#list>

                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="et_but">提交更改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
</body>
<script>
    //添加按钮点击事件
    $("#addbtn").click(function () {
        $("#myModal").modal({
            backdrop:false
        });
    });
    //添加模态框保存
    $("#addbutt").click(function () {

        $.ajax({
            url:"/tp.do?key=AdminTclass.insert",
            type:"post",
            data:$("#myModal form").serialize(),
            success:function (result) {
                $("#myModal").modal("hide");
            }
        });
    });
    function editbut(id) {
        gettclass(id);
        $("#editeModal").modal({
            backdrop:false
        });

    }
    function delbut(id) {
        if (confirm("确认删除该用户吗!!!!")){

            $.ajax({
                url:"/admin/delclassfromstu",
                type:"post",
                data:"id="+id,
                success:function (result) {
                    //alert(result.msg);
                }
            });
        }
    }
    function gettclass(id) {
        $.ajax({
            url:"/admin/getuser",
            type:"post",
            data:"id="+id,
            success:function (result) {
                var user= result.extend.user;
                $("#eid").val(user.id);
                $("#ename").val(user.code);
                $("#etime").val(user.name);

            }
        });
    }
    //更改模态框保存
    $("#et_but").click(function () {

        $.ajax({
            url:"/admin/setStuClass",
            type:"post",
            data:$("#editeModal form").serialize(),
            success:function (result) {
                $("#editeModal").modal("hide");
            }
        });
    });
    $("#sera").click(function () {
// var type = $("#type").val();
// var username = $("#usename").val();
//

    });
</script>
</html>